<#--TS-SERVICE-->
import { myhttp } from '@/utils/request'
import { FilterValue, QueryConfig } from '@/common/dayu-common'

interface ${table.className}{
<#list columns as column>
<#if column.varName == table.idColumn.varName>
  ${column.varName} : ${column.jsType};
<#elseif column.jsonIgnore==false>
  /** ${column.columnCaption!''}*/
  ${column.varName}? : ${column.jsType};
  <#if (column.codeType!'')?length gt 0>
  ${column.varName}Caption? : string;
  </#if>
</#if>
</#list>
}

interface ${table.className}Stats{
  key?:string;
  aggregateGroupName?:string;
  aggregateGroupLabel?:string;
<#list columns as column>
  <#if column.aggregateGroup!false == true>
  /**${column.columnCaption!''}*/
  ${column.varName}?:${column.jsType};
  </#if>
</#list>

<#list columns as column>
  <#list column.aggregateColumns as aggColumn>
    /**${column.columnCaption!''} ${aggColumn.columnCaption!''}*/
    ${aggColumn.varName}? : number;
  </#list>
</#list>
}

/**对${table.className}Stats的二次封装，去掉了分组字段，只保留数值，并增加了部分行转列属性*/
class ${table.className}StatData{
<#list columns as column>
  <#list column.aggregateColumns as aggColumn>
  <#if aggColumn.aggregateFunc=="COUNT">
  /**${column.columnCaption!''} ${aggColumn.columnCaption!''}*/
  ${aggColumn.varName}? : number;
  ${aggColumn.varName}1? :number;
  ${aggColumn.varName}2? : number;
  ${aggColumn.varName}3? : number;
  <#else>
  /**${column.columnCaption!''} ${aggColumn.columnCaption!''}*/
  ${aggColumn.varName}? : number;
  </#if>
  </#list>
</#list>
}

class ${table.className}Service{
  controller = '${table.beanName}';
  
  /**获取一个${table.className}对象*/
  get${table.className}(${table.idVarName} : ${table.idPropJsType}){
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/get${table.className}`,{${table.idVarName}: ${table.idVarName}});
  }
  
  /**获取一个EntityBO<${table.className}>对象*/
  get${table.className}BO(${table.idVarName} : ${table.idPropJsType}){
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/get${table.className}BO`,{${table.idVarName}: ${table.idVarName}});
  }

  /**保存一个对象*/
  save${table.className}(item : ${table.className}) {
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/save${table.className}`,{item: JSON.stringify(item)});
  }

<#if updateCellValueEnable==true>
    /**更新单个字段的值
     *
     * @param ${table.idVarName} 记录id
     * @param propName 属性名称
     * @param value 属性值
    */
    updateProp(${table.idVarName}:${table.idPropJsType}, propName:string, value:any){
        return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/updateProp`,{${table.idVarName}: ${table.idVarName}, propName:propName, value:value});
    }
</#if>

<#if isTree==true && parentColumn??>
    /** 获取子节点数据 */
    getChildNodes(<#if foreignColumn??>${foreignColumn.varName}:${foreignColumn.jsType}, </#if>pId:string){
      return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/getChildNodes`,{<#if foreignColumn??>${foreignColumn.varName}:${foreignColumn.varName}, </#if>pId:pId});
    }
    
    /**更改 自己所属的父节点
     *
     * @param ${table.idVarName} ${table.tableName}.${table.idVarName}
     * @param ${parentColumn.varName}New 新的 ${parentColumn.columnCaption}
     */
  change${parentColumn.propNameTrimId}(${table.idVarName}:${table.idPropJsType}, ${parentColumn.varName}New:${parentColumn.jsType}){
      return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/change${parentColumn.propNameTrimId}`,{${table.idVarName}:${table.idVarName}, ${parentColumn.varName}New:${parentColumn.varName}New});
  }
</#if>

<#if table.isLockByRow>
  /**修改数据锁定状态
   * @param id 记录id，另-1表示对整表进行锁定
   * @param lockState
   * @param authTag 权限类型，参考 AuthTag
  **/
  changeLockState(id:${table.idPropJsType}, lockState:number){
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/changeLockState`,{id: id, lockState:lockState});
  }
</#if>
<#if table.isLockByMaster>
  /**<#if foreignColumn??>修改数据被主数据的锁定状态<#else>修改整表被锁定的状态</#if>
     <#if foreignColumn??>* @param ${foreignColumn.varName} 主数据记录id，另-1表示对${table.className}整表进行锁定</#if>
   * @param id 记录id，另-1表示对整表进行锁定
   * @param lockState
   * @param authTag 权限类型，参考 AuthTag
  **/
  changeMasterLockState(<#if foreignColumn??>${foreignColumn.varName}:${foreignColumn.jsType}, </#if>lockState:number){
  <#if foreignColumn??>
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/changeMasterLockState`,{${foreignColumn.varName}: ${foreignColumn.varName}, lockState:lockState});
  <#else>
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/changeMasterLockState`,{lockState:lockState});
  </#if>
  }
</#if>

  /**删除一条记录*/
  delete${table.className}(${table.idVarName} : ${table.idPropJsType}){
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/delete${table.className}`,{${table.idVarName} : ${table.idVarName}});
  }

  /**根据条件查询*/
  get${table.className}ExListAndStats(<#rt>
        <#lt><#if linkToTree==true>${foreignColumn.varName}:${foreignColumn.jsType}, </#if><#rt>
        <#lt><#if useRecurseQuery==true>recursion:boolean, </#if><#rt>
        <#lt>filters:Array<FilterValue>, queryConfig:QueryConfig) {
    return myhttp.post(`${r'${myhttp.urlprix}'}base/${r'${this.controller}'}/get${table.className}ExListAndStats`,{<#rt>
        <#lt><#if linkToTree==true>${foreignColumn.varName}:${foreignColumn.varName}, </#if><#rt>
        <#lt><#if useRecurseQuery==true>recursion:recursion, </#if><#rt>
        <#lt>filters: JSON.stringify(filters), queryConfig: JSON.stringify(queryConfig)});
  }

  /**导出并下载excel文件*/
  export${table.className}ExListAndStats(<#rt>
        <#lt><#if linkToTree==true>${foreignColumn.varName}:${foreignColumn.jsType}, </#if><#rt>
        <#lt><#if useRecurseQuery==true>recursion:boolean, </#if><#rt>
        <#lt>filters:Array<FilterValue>, queryConfig:QueryConfig) {
    return myhttp.post(`${r'${myhttp.urlprix}'}xls/${r'${this.controller}'}/get${table.className}ExListAndStats`,{<#rt>
        <#lt><#if linkToTree==true>${foreignColumn.varName}:${foreignColumn.varName}, </#if><#rt>
        <#lt><#if useRecurseQuery==true>recursion:recursion, </#if><#rt>
        <#lt>filters: JSON.stringify(filters), queryConfig: JSON.stringify(queryConfig)});
  }
}

const ${table.beanName}Service = new ${table.className}Service();

export {${table.className}, ${table.className}Stats, ${table.className}StatData, ${table.beanName}Service}